package com.mapper;

import com.pojo.Student;
import com.pojo.Team;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeamMapper {

    @Select("select * from student where open_id = #{open_id}")
    Student getStudentById(String open_id);

    @Select("select team_id from student where open_id = #{open_id}")
    Integer getStudentTeam(String open_id);

    @Insert("insert into team(leader_id,name,code,introduce) value(#{leader_id},#{name},#{code},#{introduce})")
    Integer createTeam(String leader_id,String name,String code,String introduce);

    @Select("select * from team where id = #{id}")
    Team getTeamById(Integer id);

    @Select("select * from team where leader_id = #{leader_id}")
    Team getTeamByLeader(String leader_id);

    @Update("update student set team_id = #{team_id},teacher_id = null where open_id = #{open_id}")
    void joinTeam(Integer team_id,String open_id);

    @Select("select * from student where team_id = #{team_id} and open_id <> #{open_id}")
    List<Student> getTeamMember(Integer team_id,String open_id);

    @Update("update team set topic_id = #{topic_id},topic_state = 0 where id = #{id}")
    void sign(Integer topic_id,Integer id);

    @Update("update student set team_id = null,teacher_id = null where team_id = #{team_id}")
    void dissol(Integer team_id);

    @Delete("delete from team where id = #{id}")
    void delTeam(Integer id);

    @Update("update team set name = #{name},code = #{_code},introduce = #{introduce} where id = #{id}")
    void editInfo(Integer id,String name,String introduce,String _code);

}